//
//  RefreshOrderNoRead.m
//  carcareIOS
//
//  Created by 王然 on 16/4/29.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "RefreshOrderNoRead.h"
#import "NetOrderNoRead.h"
@interface RefreshOrderNoRead()

@property (nonatomic , copy) NSString * noReadOrderStr;//未读订单号数组

@end

@implementation RefreshOrderNoRead
IMP_SINGLETON

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        self.timeInterval = 600;
        __weak __typeof(self) wself = self;
        self.Refresh = ^()
        {
          [[NetOrderNoRead getNotReadOrderState] requestSuccess:^(id JSON) {
              //notRead是否存在未读订单：0无   1有
              if ([JSON[@"notRead"] integerValue] == 1) {
                  NSArray * orderDicArr = JSON[@"list"];
                  NSMutableString * tempStr = [NSMutableString stringWithCapacity:orderDicArr.count];
                  for (int index = 0; index < [orderDicArr count]; index ++)
                  {
                      [tempStr appendString:orderDicArr[index][@"orderNo"]];
                      if(index != [orderDicArr count] - 1)[tempStr appendString:@","];
                  }
                  wself.noReadOrderNum = orderDicArr.count;
                  wself.noReadOrderStr = tempStr;
              }else
              {
                  wself.noReadOrderNum = 0;
                  wself.noReadOrderStr = @"";
              }
              if (wself.RefreshCallBack) {
                  wself.RefreshCallBack(JSON);
              }
              
          } failure:^(id JSON) {

          }];
            
            
        };
    }
    return self;
}
- (void)updateOrderIsReadSuccess:(void (^)(id))readSuccess failure:(void (^)(id))readFailure
{
    [[NetOrderNoRead updateReadOrderState:self.noReadOrderStr]requestSuccess:^(id JSON) {
        
        if(readSuccess)readSuccess(JSON);
    } failure:^(id JSON) {
        if(readFailure)readFailure(JSON);
    }];
}
@end
